/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './payController';
import * as API from './types';

/** 微信支付回调 POST /api/pay/notifyMnp */
export function useNotifyMnpUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.notifyMnpUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 支付状态 GET /api/pay/payStatus */
export function payStatusUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.payStatusUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.payStatusUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['payStatusUsingGet', options],
  });
}

/** 支付方式 GET /api/pay/payWay */
export function payWayUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.payWayUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.payWayUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['payWayUsingGet', options],
  });
}

/** 发起支付 POST /api/pay/prepay */
export function usePrepayUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.prepayUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}
